<?php
class Answer_Component_Controller_Admincp_Level_Index extends Phpfox_Component {
    public function process() {
        $sLink = "admincp.answer.level";
        if ($iId = $this->request()->getInt('delete')) {
            if (Phpfox::getService('answer.level')->delete($iId)) {
                $this->url()->send($sLink,array(),Phpfox::getPhrase('answer.level_deleted_successfully'));
            }
            else {
                $this->url()->send($sLink,array(),Phpfox::getPhrase('answer.level_not_found'));
            }
        }
        if ($aVals = $this->request()->getArray('val')) {
            $aVals = array_merge($aVals, $this->request()->getArray('val'));
            if (Phpfox::getService('answer.level')->saveDatabase($aVals))
            {
                $this->url()->send($sLink,array(), Phpfox::getPhrase('answer.add_successfully'));
            }
        }

        $aGroups = Phpfox::getService('answer.group')->getAllGroup();

        $aLevels = Phpfox::getService('answer.level')->getListNoPage();
        $aLevels = $aLevels['data'];

        $this->template()
            ->setTitle(Phpfox::getPhrase('answer.level'))
            ->setBreadcrumb(Phpfox::getPhrase('answer.level'))
            ->assign(array(
                'aGroups' => $aGroups,
                'aLevels' => $aLevels
             ));

    }
}